package com.fr.lintcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 付荣
 * @version 创建时间：2019年1月31日 下午1:44:12
 */
public class Q1650 {
	/**
	 * @param s
	 *            : the article
	 * @return: the number of letters that are illegal
	 */
	public int count(String s) {
		int count = 0;
		Set<Integer> nextType = new HashSet<>();
		nextType.add(1);
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (c > 'A' && c < 'Z') {
				if (nextType.contains(1)) {

				} else {
					count++;
				}
				nextType.clear();
				nextType.add(2);
				nextType.add(3);
				nextType.add(4);
			} else if (c > 'a' && c < 'z') {
				if (nextType.contains(2)) {

				} else {
					count++;
				}
				nextType.clear();
				nextType.add(2);
				nextType.add(3);
				nextType.add(4);
			} else if (c == ' ') {
				if (nextType.contains(3)) {

				} else {
					count++;
				}
				nextType.clear();
				nextType.add(2);
				nextType.add(3);
				nextType.add(4);
			} else if (c == ',' || c == '.') {
				if (nextType.contains(4)) {

				} else {
					count++;
				}
				nextType.clear();
				nextType.add(1);
			}
		}
		return count;
	}
}
